package com.example.zyfypt_321lz.activity;

import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;

import com.example.zyfypt_321lz.R;
import com.example.zyfypt_321lz.iface.RegisterListener;
import com.example.zyfypt_321lz.model.RegisterModel;

public class RegisterActivity extends AppCompatActivity implements View.OnClickListener {
    private Button btnque,btnre;
    private EditText edtname,edtpass,edtmail;
    RegisterListener registerListener = new RegisterListener() {
        @Override
        public void onResponse(String msg) {
            if(msg.equals("1")){
                System.out.println("result:"+msg);
                finish();
            }else{
                System.out.println("result:"+msg);
            }
        }
        @Override
        public void onFail(String msg) {
            Toast.makeText(RegisterActivity.this, msg, Toast.LENGTH_SHORT).show();
        }
    };
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_register);
        Toast.makeText(this,"注册", Toast.LENGTH_SHORT).show();
        init();
    }
    private void init() {
        btnque=(Button)findViewById(R.id.button5);
        btnre=(Button)findViewById(R.id.button3);
        edtname=(EditText)findViewById(R.id.edtname);
        edtpass=(EditText)findViewById(R.id.edtpass);

        btnque.setOnClickListener(this);
        btnre.setOnClickListener(this);
    }

    @Override
    public void onClick(View v) {
        switch (v.getId()) {
            case R.id.button5:
                break;
            case R.id.button3:
                Toast.makeText(RegisterActivity.this, "注册成功", Toast.LENGTH_SHORT).show();
                RegisterModel registerModel = new RegisterModel();
                registerModel.getResult(edtname.getText().toString(), edtpass.getText().toString(), edtmail.getText().toString(), registerListener);
                break;
        }
    }
}